<template>
  <div class="show_card ">
    <div :class="['show_card_item', selectRecordId == item.recordId && 'show_card_item_select']"
      v-for="(item, idx) in list"
      :key="idx"
      @click="toSelectItem(item)">
      <div class="show_card_item_info_top">
        <div class="show_card_item_info_name">{{
          item.serviceType == 'service' ?item.serviceItemName : item.cardName
      }} <span class="show_card_item_info_sku"
            v-if="item.skuName">
            ({{item.skuName}})</span></div>

        <el-link :underline="false"
          type="primary"
          class="to-view-detail"
          @click.stop="toShowCardProject(item)"
          v-if="item.serviceType == 'card'"
          size="mini">查看详情</el-link>
      </div>

      <div class="show_card_item_info_center">
        <div class="show_card_item_info_time"
          v-if="item.endDate">有效期至 {{ item.endDate }}</div>
        <div class="show_card_item_info_time"
          v-else>有效期内可以使用</div>

        <div class="show_card_item_info_useTime"
          v-if="item.isUnLimit == 0">
          已用{{ item.subscribeTimes }}次</div>
        <div class="show_card_item_info_useTime"
          v-if="item.isUnLimit == 1">不限制使用次数</div>
      </div>

      <div class="show_card_item_info_bottom">
        <div class="show_card_item_allTime"
          v-if="item.isUnLimit == 0">总共可使用{{(item.times)}}次</div>
        <div class="show_card_item_allTime"
          v-if="item.isUnLimit == 1">不限制使用次数</div>

        <div class="show_card_opt">
          <template v-if="item.type == '2' || type == '2'">
            <div class="show_card_opt_show">
              <span class="show_card_opt_show_txt">实收金额：</span>
              <span class="show_card_opt_show_value">{{item.payAmountStr}}</span>
            </div>
            <el-link class="show_card_opt_show"
              v-if="item.buyType=='buy'"
              :underline="false"
              type="primary"
              size="mini"
              @click.stop="toViewOrderDetail(item)">订单详情</el-link>
          </template>
          <div class="show_card_opt_show"
            v-if="item.type == '3' || type == '3'">
            <span class="show_card_opt_show_txt">使用时间：</span>
            <span class="show_card_opt_show_value">{{item.endDateString}}</span>
          </div>
          <div class="show_card_opt_show"
            v-if="item.type == '5' || type == '5'">
            <span class="show_card_opt_show_txt">领取人：</span>
            <span class="show_card_opt_show_value">{{item.receiveCustomerName}}</span>
          </div>

        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      selectRecordId: ''
    }
  },
  props: {
    list: {
      type: Array,
      default: function () {
        return []
      }
    },
    type: {
      type: String,
      default: ''
    }
  },
  methods: {
    toShowCardProject (item) {
      this.$emit('toShowCardProject', item)
    },
    toViewOrderDetail (item) {
      this.$emit('toViewOrderDetail', item)
    },
    toSelectItem (item) {
      // if (this.type == '3') {
        if (item.recordId != this.selectRecordId) {
          this.selectRecordId = item.recordId
        } else {
          this.selectRecordId = ''
        }
        this.$emit('toSelectCard', item.recordId)
      // }
    }
  }
}
</script>

<style lang="scss" scoped>
.show_card {
  display: flex;
  flex-wrap: wrap;
}
.show_card_item {
  padding: 4px;
  box-shadow: 0 0 10px 5px rgba(0, 0, 0, 0.05);
  border: 1px solid #eee;
  padding: 15px;
  width: calc((100% - 30px) / 3);
  cursor: pointer;
  &:not(:nth-child(3n)) {
    margin-right: 15px;
  }

  margin-bottom: 15px;
  border-radius: 10px;
  position: relative;

  .show_card_item_info_top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;

    .show_card_item_info_name {
      font-size: 15px;
      color: #333;
      line-height: 1;
    }

    .show_card_item_info_sku {
      font-size: 14px;
      color: #666;
      line-height: 1;
      margin-bottom: 10px;
    }
  }
  .show_card_item_info_center {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .show_card_item_info_time {
      font-size: 12px;
      color: #999;
    }
    .show_card_item_info_useTime {
      font-size: 15px;
      color: #333;
      font-weight: 600;
    }
  }

  .show_card_item_info_bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 15px;
    .show_card_item_allTime {
      font-size: 12px;
      color: #333;
    }
    .show_card_opt {
      display: flex;
      align-items: center;
      .show_card_opt_show {
        display: flex;
        align-items: center;
        .show_card_opt_show_txt {
          font-size: 12px;
          color: #333;
        }
        .show_card_opt_show_value {
          font-size: 12px;
          color: #5da9ef;
        }
        &:not(:last-child) {
          margin-right: 15px;
        }
      }
    }
  }
}

.show_card_item_select {
  border-color: #5da9ef;
}
</style>
